package cn.jiawei.jsql.net.protocol.handler;

import cn.jiawei.jsql.net.protocol.codec.PacketCodec;
import cn.jiawei.jsql.net.protocol.packages.Package;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;

import java.util.List;


/**
 * @author : willian fu
 * @version : 1.0
 * @date : 2020/12/18 0018 14:59
 */
public class JsqlPacketDecoder extends MessageToMessageCodec<ByteBuf, Package> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Package packet, List<Object> list) throws Exception {
        list.add(PacketCodec.encode(channelHandlerContext.channel(), packet.getBytes()));
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        list.add(PacketCodec.decode(byteBuf));
    }
}
